package com.atguigu.gulimall.search.web;

import com.atguigu.gulimall.search.service.SearchService;
import com.atguigu.gulimall.search.vo.SearchParamVo;
import com.atguigu.gulimall.search.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lk
 * @version 1.0.0
 * @Description 检索系统首页控制器
 * @createTime 2024/1/21 10:33
 */
@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 自动将页面提交过来的所有请求参数封装成我们指定的对象
     * @return
     */
    @GetMapping(value = {"/","/list.html"})
    public String listPage(SearchParamVo searchParamVo, Model model, HttpServletRequest httpServletRequest){
        searchParamVo.set_queryString(httpServletRequest.getQueryString());
        //1.在返回页面中设置检索结果
        SearchResultVo result =  searchService.search(searchParamVo);
        model.addAttribute("result",result);
        return "list";
    }
}
